﻿@page "/basicform-fluentui-components"

<h1>Starfleet Starship Database</h1>
<p>
    This form uses the Fluent UI input components. It uses a <code>DataAnnotationsValidator</code> and a <code>FluentValidationSummary</code>
</p>

<h2>New Ship Entry Form</h2>

<EditForm Model="@starship" OnValidSubmit="@HandleValidSubmit">
    <DataAnnotationsValidator />
    <FluentValidationSummary />


    <FluentStack Orientation="Orientation.Vertical">
        <FluentTextField @bind-Value="starship.Identifier">Identifier:</FluentTextField>
        <FluentTextArea Rows=5 Cols=60 @bind-Value="starship.Description">Description (optional):</FluentTextArea>
        <label for="classification">Primary Classification:</label>
        <FluentSelect Id="classification" @bind-Value="starship.Classification" TOption="string">
            <FluentOption Value="">Select classification ...</FluentOption>
            <FluentOption Value="Exploration">Exploration</FluentOption>
            <FluentOption Value="Diplomacy">Diplomacy</FluentOption>
            <FluentOption Value="Defense">Defense</FluentOption>
        </FluentSelect>
        
        <FluentNumberField @bind-Value="starship.MaximumAccommodation"> Maximum Accommodation:</FluentNumberField>
        <FluentCheckbox @bind-Value="starship.IsValidatedDesign">Engineering Approval</FluentCheckbox>
        <label for="proddate">Production Date:</label>
        <FluentDatePicker Id="proddate" @bind-Value="prodDate" />
        
        <FluentButton Type="ButtonType.Submit" Appearance="Appearance.Accent">Submit</FluentButton>
    </FluentStack>
</EditForm>

<div style="margin-top: 3rem;"><a href="http://www.startrek.com/">Star Trek</a>, ©1966-2023 CBS Studios, Inc. and <a href="https://www.paramount.com">Paramount Pictures</a></div>
@code {
    DateTime? prodDate = DateTime.Now;

    protected override void OnInitialized()
    {
        starship.ProductionDate = new DateOnly(prodDate!.Value.Year, prodDate!.Value.Month, prodDate!.Value.Day);
    }

    private Starship starship = new();

    private void HandleValidSubmit()
    {
        DemoLogger.WriteLine("HandleValidSubmit called");

        // Process the valid form
    }
}